package com.ctshk.sapp.system.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.system.dto.OperationLogDTO;
import com.ctshk.rpc.system.dto.StockScenicAreaDTO;
import com.ctshk.rpc.system.dto.StockScenicAreaPhotoDTO;
import com.ctshk.rpc.system.dto.StockScenicQueryAreaPhotoDTO;
import com.ctshk.rpc.system.req.StockScenicAreaListReq;
import com.ctshk.rpc.system.req.StockScenicAreaPhotoDeleteReq;
import com.ctshk.rpc.system.req.StockScenicAreaPhotoListReq;
import com.ctshk.rpc.system.req.StockScenicAreaPhotoBatchAddReq;
import com.ctshk.rpc.system.service.IStockScenicAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author xuhui
 * @since 1/29/2021
 */

@Api(value="景点资料", tags="景点资料主数据")
@RestController
@RequestMapping("/main/data/stock/scenic/area/photo")
public class StockScenicAreaPhotoController extends BaseController {

    @DubboReference
    IStockScenicAreaService stockScenicAreaService;

    @ApiOperation(value="查询地区图片", notes="查询地区图片")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询地区图片", operDesc = "查询地区图片")
    @PostMapping("/query-area-photo")
    public Result<PageResponse<StockScenicQueryAreaPhotoDTO>> queryAreaPhoto(@RequestBody StockScenicAreaPhotoListReq stockScenicAreaPhotoListReq){
        PageResponse<StockScenicQueryAreaPhotoDTO> result = stockScenicAreaService.queryAreaPhoto(stockScenicAreaPhotoListReq);
        return Result.success(result);
    }


    @ApiOperation(value="查询地区列表", notes="根据用户输入的关键字查询匹配的地区列表(无需参数)")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询地区列表", operDesc = "根据用户输入的关键字查询匹配的地区列表")
    @GetMapping("/arealist")
    public Result arealist(){
        StockScenicAreaListReq stockScenicAreaListReq=new StockScenicAreaListReq();
        StockScenicAreaListReq.searchAll=true;
                PageResponse<StockScenicAreaDTO> pageResponse
                        =stockScenicAreaService.areaList(stockScenicAreaListReq,getCurrentUser(getRequest()));
        return new Result(pageResponse);
    }

    @ApiOperation(value="查询地区列表", notes="根据用户输入的关键字查询匹配的地区列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询地区列表", operDesc = "根据用户输入的关键字查询匹配的地区列表")
    @PostMapping("/arealist")
    public Result arealist(@RequestBody StockScenicAreaListReq stockScenicAreaListReq){
                PageResponse<StockScenicAreaDTO> pageResponse
                        =stockScenicAreaService.areaList(stockScenicAreaListReq,getCurrentUser(getRequest()));
        return new Result(pageResponse);
    }

    @ApiOperation(value = "根据图片id查询图片", notes = "根据图片id查询图片")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "根据图片id查询图片", operDesc = "根据图片id查询图片")
    @GetMapping("/info/{id}")
    public Result<StockScenicAreaPhotoDTO> queryPhoto(@PathVariable Long id){
        StockScenicAreaPhotoDTO scenicAreaPhotoDTO = stockScenicAreaService.queryPhoto(id);
        return Result.success(scenicAreaPhotoDTO);
    }

    @ApiOperation(value="查询地区图片", notes="查询地区图片")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询地区图片", operDesc = "查询地区图片")
    @PostMapping("/area-photo")
    public Result<PageResponse<StockScenicAreaPhotoDTO>> areaPhoto(@RequestBody StockScenicAreaPhotoListReq stockScenicAreaPhotoListReq){
        PageResponse<StockScenicAreaPhotoDTO> result = stockScenicAreaService.areaPhoto(stockScenicAreaPhotoListReq);
        return Result.success(result);
    }


    @ApiOperation(value="删除某地区图片", notes="根据图片ID删除图片")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.DELETE, operTitle = "删除图片", operDesc = "删除图片")
    @PostMapping("/delete")
    public Result delete(@RequestBody StockScenicAreaPhotoDeleteReq stockScenicAreaPhotoDeleteReq){
        return new Result(stockScenicAreaService.delete(stockScenicAreaPhotoDeleteReq,getCurrentUser(getRequest())));
    }

    @ApiOperation(value="图片库操作记录", notes="查询图片库操作记录")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询图片库操作记录", operDesc = "查询图片库操作记录")
    @GetMapping("/operation/records")
    public Result<List<OperationLogDTO>> opeartionRecords(){
        return new Result(stockScenicAreaService.opeartionRecords(getCurrentUser(getRequest())));
    }



    @ApiOperation(value="新增图片库", notes="新增图片库")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "新增图片库", operDesc = "新增图片库")
    @PostMapping("/addPhoto")
    public Result<List<StockScenicAreaPhotoDTO>> addPhoto(@RequestBody @Valid StockScenicAreaPhotoBatchAddReq req){
        return stockScenicAreaService.addPhoto(req,getCurrentUser(getRequest()).getId());
    }






}